package com.gouwudai.gobbs.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.gouwudai.gobbs.common.IPageList;
import com.gouwudai.gobbs.dao.ITopicReDAO;
import com.gouwudai.gobbs.pojo.TbbsTopicRe;
import com.gouwudai.gobbs.service.ITopicReService;
import com.litt.core.common.Utility;
import com.litt.core.exception.DBException;
import com.litt.core.util.ParamUtils;

public class TopicReServiceImpl implements ITopicReService
{
	ITopicReDAO topicReDAO;
	
	public TbbsTopicRe load(Integer id)
	{
		return (TbbsTopicRe)topicReDAO.load(id);
	}

	/**
	 * 结帖给分
	 * @param topicId
	 * @param userMarkMap
	 * @return
	 */
	public void doGiveMark(Integer topicId,HashMap userMarkMap)
	{		
			Iterator topicReIds = userMarkMap.keySet().iterator();
			Integer topicReId = null;
			BigDecimal userMark = null;			
			while(topicReIds.hasNext())
			{				
				topicReId = Utility.parseInt((String)topicReIds.next());
				userMark = ParamUtils.getMapToBigDecimal(userMarkMap, topicReId.toString());		
				topicReDAO.doGiveMark(topicReId, userMark);				
			}				
	}	
	
	/**
	 * 逻辑删除回复
	 * @param topicReIds
	 * @throws DBException
	 */
	public void deleteLogic(String[] topicReIds)
	{
		if(topicReIds!=null&&topicReIds.length>0)
		    topicReDAO.deleteLogic(Utility.combinString(topicReIds));
	}
	
	/**
	 * 逻辑删除单条回复
	 * @param topicReId
	 * @throws DBException
	 */
	public void deleteLogic(int topicReId)
	{
			topicReDAO.deleteLogic(topicReId);			
	}	

	/**
	 * 恢复已删除回复
	 * @param topicReIds
	 * @throws DBException
	 */
	public void doResume(String[] topicReIds)
	{
			topicReDAO.doResume(Utility.combinString(topicReIds));
	}

	/**
	 * 物理删除
	 * @param Id
	 * @return
	 */
	public void delete(Integer Id)
	{
			topicReDAO.delete(Id);
	}

    /**
     * 查询当前主题的回复信息
     * @param topicId
     * @param pageIndex
     * @param pageSize
     * @return
     * @throws DBException
     */
    public List listByTopic(Integer topicId,int pageIndex,int pageSize)
    {
    	return topicReDAO.listByTopic(topicId, pageIndex, pageSize);
    }
    
    /**
     * 查询当前主题的回复信息数量（供分页）
     * @param topicId
     * @param pageIndex
     * @param pageSize
     * @return
     * @throws DBException
     */
    public int listCountByTopic(Integer topicId)
    {
    	return topicReDAO.listCountByTopic(topicId);    	
    }
    
    /**
     * 统计用户对该主题的回复数量
     * 使用过的地方：“回复可见”
     * @param topicId
     * @param userId
     */
    public int listCountByReUser(Integer topicId,Integer userId)
    {
    	return topicReDAO.listCountByReUser(topicId, userId);
    }
    
    /**
     * 查询获得积分的用户
     * @param topicId
     * @return
     * @throws DBException
     */
    public List listGetMark(Integer topicId)
    {
    	return topicReDAO.listGetMark(topicId);
    }
	
	public IPageList listPage(int pageIndex,int pageSize)
	{
		return topicReDAO.listPage(pageIndex, pageSize);
	}

	public void setTopicReDAO(ITopicReDAO topicReDAO) {
		this.topicReDAO = topicReDAO;
	}

}